//
// Created by guanyicheng on 2022/3/14.
//
#include "../../common.h"

class Solution {
public:
    bool isHappy(int n) {
        int sum = 0, n1 = n;
        unordered_set<int> set1{};
        while (true) {
            sum = 0;
            while (n1) {
                sum += (n1 % 10) * (n1 % 10);
                n1 /= 10;
            }
            if (sum == 1) {
                return true;
            }
            if (set1.count(sum)) {
                return false;
            }
            set1.emplace(sum);
            n1 = sum;
        }
    }
};

int main() {
    cout << Solution().isHappy(19);
}
